package br.com.digicade.geosite.gpsavl.resource.impl;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;

import br.com.digicade.geosite.gpsavl.resource.SecurityResource;

public class SecurityResourceImpl implements SecurityResource {
	
	@Override
	public boolean login(HttpServletRequest request, String usuario, String password) {
		try {
			//return securityContext.login(usuario, password);
			return Boolean.TRUE;
		} catch (Exception e) {
			Response response = Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
			throw new WebApplicationException(response);
		}
	}


	@Override
	public boolean keepAlive() {
		try {
			//return securityContext.keepAlive();
			return Boolean.TRUE;
		} catch (Exception e) {
			Response response = Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
			throw new WebApplicationException(response);
		}
	}

	@Override
	public boolean logout(HttpServletRequest request) {
		try {
			request.getSession().invalidate();
			
			//return securityContext.logout();
			return Boolean.TRUE;
		} catch (Exception e) {
			Response response = Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
			throw new WebApplicationException(response);
		}
	}
}
